<template>
  <button @click="openModal">打开对话框</button>

  <teleport to="body">
    <div v-if="flag === true">
      <div>
        这里是对话框
        <button @click="flag = false">关闭对话框</button>
      </div>
    </div>
  </teleport>
</template>

<script lang="ts">
import { defineComponent, ref } from "vue";

export default defineComponent({
  name: "buttonModal",
  setup() {
    const flag = ref(false);
    const openModal = () => {
      flag.value = true;
    };

    return {
      openModal,
      flag,
    };
  },
});
</script>
